﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySQLStudio.DataAccess;
using MySQLStudio.Common;

namespace MySQLStudio.BusinessLogic
{
    public class Database : BaseDatabaseObject
    {
        private string m_defaultCollation;

        internal Database(string databaseName, string defaultCollation)
        {
            this.m_name = databaseName;
            this.m_schema = databaseName;
            this.m_type = "DATABASE";
            this.m_defaultCollation = defaultCollation;
        }

        public string DefaultCollation
        {
            get
            {
                return m_defaultCollation;
            }
            set
            {
                m_defaultCollation = value;
            }
        }

        public void Delete(string connectionString)
        {
            try
            {
                int errCode = MySqlDataAccess.ExecuteNonQuery(connectionString, InformationSchemaHelper.GetDropDatabseCommand(this.m_name));
                if (errCode != 0)
                    throw new ApplicationException(ErrorMessages.GetString(ErrorMessages.InformationSchema_Failed_to_drop_database, this.m_name));
            }
            catch (ApplicationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ErrorMessages.GetString(ErrorMessages.InformationSchema_Failed_to_drop_database, this.m_name), ex);
            }
        }
    }
}
